package com.ruoyi.pm.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.pm.domain.ExcPort;
import com.ruoyi.pm.service.IExcPortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 保司接口配置Controller
 *
 * @author ruoyi
 * @date 2022-01-20
 */
@RestController
@RequestMapping("/pm/excPort")
public class ExcPortController extends BaseController {
    @Autowired
    private IExcPortService excPortService;

    /**
     * 查询保司接口配置列表
     */
    @PreAuthorize("@ss.hasPermi('pm:excPort:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExcPort excPort) {
        startPage();
        List<ExcPort> list = excPortService.selectExcPortList(excPort);
        return getDataTable(list);
    }

    /**
     * 导出保司接口配置列表
     */
    @PreAuthorize("@ss.hasPermi('pm:excPort:export')")
    @Log(title = "保司接口配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExcPort excPort) {
        List<ExcPort> list = excPortService.selectExcPortList(excPort);
        ExcelUtil<ExcPort> util = new ExcelUtil<ExcPort>(ExcPort.class);
        util.exportExcel(response, list, "保司接口配置数据");
    }

    /**
     * 获取保司接口配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('pm:excPort:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(excPortService.selectExcPortById(id));
    }

    /**
     * 新增保司接口配置
     */
    @PreAuthorize("@ss.hasPermi('pm:excPort:add')")
    @Log(title = "保司接口配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExcPort excPort) {
        return toAjax(excPortService.insertExcPort(excPort));
    }

    /**
     * 修改保司接口配置
     */
    @PreAuthorize("@ss.hasPermi('pm:excPort:edit')")
    @Log(title = "保司接口配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExcPort excPort) {
        return toAjax(excPortService.updateExcPort(excPort));
    }

    /**
     * 删除保司接口配置
     */
    @PreAuthorize("@ss.hasPermi('pm:excPort:remove')")
    @Log(title = "保司接口配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(excPortService.deleteExcPortByIds(ids));
    }
}
